﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Seagull.BarTender.Print;
using 大连顺秋服装厂产线.批次包装贴.service;

namespace 大连顺秋服装厂产线
{
    public partial class Form批次包装贴 : DevExpress.XtraEditors.XtraForm
    {
        private OrderCommitDTO返回 包装贴DTO = new OrderCommitDTO返回();
        private String batchNo = "";
        public Form批次包装贴()
        {
            InitializeComponent();
        }

        private void textBox批次编号_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                try
                {
                    this.batchNo = this.textBox批次编号.Text.Trim();
                    this.包装贴DTO = 批次包装贴Service.get订单预览By批号(this.batchNo);
                    if (String.IsNullOrWhiteSpace(this.包装贴DTO.orderNo))
                    {
                        MessageBox.Show("暂无信息");
                        return;
                    }
                    else
                    {
                        this.textBoxorderNo.Text = this.包装贴DTO.orderNo;
                        this.textBoxcustomerName.Text = this.包装贴DTO.customerName;
                        this.textBoxmaterialNo.Text = this.包装贴DTO.materialCode;
                        this.textBoxshopName.Text = this.包装贴DTO.shopName;
                        this.textBox坚山订单号.Text = this.包装贴DTO.kashiyamaOrderNo;
                    }
                }
                catch
                {
                    MessageBox.Show("暂无信息");
                }
                this.print包装贴();
                this.textBox批次编号.Clear();
            }
        }

        private void print包装贴()
        {
            //String str = System.AppDomain.CurrentDomain.BaseDirectory;
            Engine btEngine = new Engine();
            btEngine.Start();
            LabelFormatDocument btFormat = btEngine.Documents.Open("C://批次包装贴.btw");
            //指定打印机名 
            //btFormat.PrintSetup.PrinterName = "HPRT HLP106S-UE";
            //btFormat.PrintSetup.PrinterName = "迅捷PDF虚拟打印机";
            btFormat.PrintSetup.PrinterName = "POSTEK G-3106";
            //打印份数                   
            btFormat.PrintSetup.IdenticalCopiesOfLabel = 2;
            //改变标签打印数份连载 
            btFormat.PrintSetup.NumberOfSerializedLabels = 2;
            //对BTW模版相应字段进行赋值 

            btFormat.SubStrings["orderNo"].Value = this.包装贴DTO.orderNo;
            btFormat.SubStrings["kashiyamaOrderNo"].Value = this.包装贴DTO.kashiyamaOrderNo;
            btFormat.SubStrings["customerName"].Value = this.包装贴DTO.customerName;
            btFormat.SubStrings["materialNo"].Value = this.包装贴DTO.materialCode;
            btFormat.SubStrings["batchNo"].Value = this.batchNo;
            btFormat.SubStrings["shopName"].Value = this.包装贴DTO.shopName;


            Messages messages;
            int waitout = 10000; // 10秒 超时 
            Result nResult1 = btFormat.Print("包装贴" + this.batchNo, waitout, out messages);
            btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;
            //不保存对打开模板的修改 
            btFormat.Close(SaveOptions.DoNotSaveChanges);
            //结束打印引擎                  
            btEngine.Stop();
        }
    }
}